﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Drawing;
using EasyGrocer.BusinessLayer.ServiceRepository;
using EasyGrocer.DataLayer;

namespace EasyGrocer
{
    public partial class ProductPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpContext context = new HttpContextContainer().GetCurrentHttpContext();
            if (context.Request.QueryString["id"] != null)
            {
                Guid pId = new Guid(context.Request.QueryString["id"]);
                //get product repository
                IProductServiceRep productRep = BusinessServiceFactory.CreateProductService();
                Product p = productRep.GetByProductId(pId);
                if(p!=null)
                {
                    SetProductPageData(p);
                }
            }
        }
        //add text into page
        private void SetProductPageData(Product p)
        {
            pName.Text = p.Name;
            pWeight.Text = p.Weight;
            pPrice.Text = p.Price.ToString();
            pAisle.Text = p.Aisle.ToString();
            pSection.Text = p.Section;
            pAvailability.Text = p.Quantity != 0 ? "No" : "Yes";
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/MapPage.aspx");
        }

        protected void AddToList_Click(object sender, EventArgs e)
        {
            SetButtonAttribute(sender);
            HttpContext context = new HttpContextContainer().GetCurrentHttpContext();
            Guid pId = new Guid(context.Request.QueryString["id"]);
            IProductServiceRep productRep = BusinessServiceFactory.CreateProductService();
            Product p = productRep.GetByProductId(pId);
        }

        private void SetButtonAttribute(object sender)
        {
            if (AddToList.Text != "Added to List")
            {
                AddToList.Text = "Added to List";
                AddToList.BackColor = Color.Yellow;
            }
        }
    }
}
